{extend name="common@base/common" /}

{block name="body"}
    <div class="tools">
        <a class="btn" href="{:U('Model/add')}">新 增</a>

        <a class="btn" href="{:U('Model/update_sql')}">批量更新插件的安装SQL文件</a>
        <a class="btn" href="{:U('Model/freshDBtoFile')}">批量从数据库更新到文件</a>
        <a class="btn" href="{:U('Model/freshFiletoDB')}">批量从文件更新到数据库</a>
		<a class="btn" href="{:U('Model/phinx')}">批量生成数据库phinx迁移文件</a>
    <div class="search-form fr cf">
		<div class="sleft" style="margin-right:10px;">
			<select name="group" style="border:none; padding:4px; margin:0;">
				<option value="{:U ( 'index')}" >全部应用</option>
				{volist name="list" id="title"}
				<option value="{:U ( 'index',array('app'=>$key))}" {eq name="key" value="$app"}selected{/eq} >{$title}</option>
				{/volist}
			</select>
		</div>
			<div class="sleft">
                {php} $search_url = U('index');{/php}
                {php}$search_key='title';{/php}
				<input type="text" name="{$search_key}" class="search-input" value="{:I($search_key)}" placeholder="请输入关键字">
				<a class="sch-btn" href="javascript:;" id="search" url="{$search_url}"><i class="btn-search"></i></a>
			</div>
	</div>        
    </div>


	<!-- 数据列表 -->
	<div class="data-table">
        <div class="data-table table-striped">
<table>
    <thead>
        <tr>
		<th>编号</th>
		<th>标识</th>
		<th>名称</th>
        <th>所属应用</th>
		<th>操作</th>
		</tr>
    </thead>
    <tbody>
	{notempty name="_list"}
		{volist name="_list" id="vo"}
		<tr>
			<td>{$vo.id} </td>
			<td>{$vo.name}</td>
			<td><a data-id="{$vo.id}" href="{:U('model/edit?id='.$vo['id'])}#2">{$vo.title}</a></td>
            <td>{$vo.addon_title|default=''}</td>
			<td>
            {notempty name="vo.table_exists"}
            {notempty name="vo.update_file"}<a href="{:U('freshDBtoFile?model_id='.$vo['id'])}">更新文件</a>&nbsp;&nbsp;&nbsp;{/notempty}
            {notempty name="vo.update_db"}<a href="{:U('freshFiletoDB?model_id='.$vo['id'])}">更新数据表</a>&nbsp;&nbsp;&nbsp;{/notempty}
                <a href="{:U('attribute/index?model_id='.$vo['id'])}">字段管理</a>&nbsp;&nbsp;&nbsp;
				<a href="{:U('model/edit?id='.$vo['id'])}#2">编辑</a>
				<a class="copy-model" href="###" rel="{$vo['id']}" data-name="{$vo.name}">复制</a>
				{else /}
<a href="{:U('importModel',['model_name'=>$vo['name'],'model_addon'=>$vo['addon']])}">导入模型</a>
                {/notempty}
				{if condition="$vo.addon!='admin' && $vo.addon!='core'"}
                &nbsp;&nbsp;&nbsp;<a href="{:U('model/del?ids='.$vo['id'])}" class="confirm">删除</a>
				{/if}
            </td>
		</tr>
		{/volist}
		{else/}
		<td colspan="7" class="text-center"> aOh! 暂时还没有内容! </td>
		{/notempty}
	</tbody>
    </table>

        </div>
    </div>
    <div class="page">
        {$_page|raw}
    </div>

{/block}

{block name="script"}
    <script src="__STATIC__/thinkbox/jquery.thinkbox.js?v={:SITE_VERSION}"></script>
    <script type="text/javascript">
        $(function(){
            //搜索功能
            $("#search").click(function(){
                var url = $(this).attr('url');
                var query  = $('.search-form').find('input').serialize();
                query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
                query = query.replace(/^&/g,'');
                if( url.indexOf('?')>0 ){
                    url += '&' + query;
                }else{
                    url += '?' + query;
                }
                url = change_search_url(url);
                window.location.href = url;
            });

            //回车自动提交
            $('.search-form').find('input').keyup(function(event){
                if(event.keyCode===13){
                    $("#search").click();
                }
            });
            $('select[name=group]').change(function(){
                location.href = this.value;
            });
            
            $('.copy-model').click(function () {
            	var id = $(this).attr('rel')
				var title = $(this).data('name')
				var url = "{:U('copyModel?only_body=1&id=555123')}"
				var reg = new RegExp( '555123' , "g" )
				url = url.replace(reg, id)
				layer_index = layer.open({
					type: 2,
					title: '复制'+title,
					area: ['500px', '500px'],
					content: url
				});
			})
        })

</script>
{/block}
